angular.module("app").controller("welfare.welfareItemList.Ctrl", ["$scope", "$state", "welfare", "$timeout", function ($scope, $state, welfare, $timeout) {
    $scope.search = { id: "", code: "" };
    $scope.welfareItemGridConfig = {
        bindingOptions: {
            selectedRowKeys: "selectedItems",
            dataSource: "welfareItemGridConfig.dataSource"
        },
        twoWayBindingEnabled: false,
        searchPanel: {
            visible: true,
            width: 200,
            placeholder: "输入关键字进行查询"
        },
        paging: {
            pageSize: 15
        },
        groupPanel: {
            visible: true,
            emptyPanelText: "拖动列名进行分组和排序"
        },
        hoverStateEnabled: true,
        showBorders: true,
        showRowLines: true,
        rowAlternationEnabled: true,
        noDataText: "没有数据",
        columns: [{
            dataField: "code",
            alignment: "center",
            caption: "券号"
        }, {
                dataField: "isChanage",
                alignment: "center",
                customizeText: function (cellInfo) {
                    var str = "未兑换";
                    if (cellInfo.value != 0) {
                        str = "已兑换";
                    }
                    return str;
                },
                caption: "是否兑换"
            }, {
                dataField: "isUse",
                alignment: "center",
                customizeText: function (cellInfo) {
                    var str = "未使用";
                    if (cellInfo.value != 0) {
                        str = "已使用";
                    }
                    return str;
                },
                caption: "是否使用"
            }, {
                dataField: "useTime",
                alignment: "center",
                cellTemplate: "useTimeCellTemplate",
                caption: "使用时间"
            }, {
                dataField: "createTime",
                alignment: "center",
                cellTemplate: "createTimeCellTemplate",
                caption: "创建时间"
            }, {
                dataField: "memberCode",
                alignment: "center",
                caption: "兑换人"
            }]
    };
    $scope.getWelfareItemList = function () {
        welfare.getWelfareItemList({}, $scope.search, function (data) {
            if (data.statusCode == 0) {
                $scope.welfareItemGridConfig.dataSource = data.data;
            }
            else if (data.statusCode == -4) {
                alert("用户没有权限");
            } else {
                alert(data.statusMessage)
            }
        })
    };
    $scope.getWelfareItemList();
    $scope.uploadWelfareItem = function (file) {
        var form = new FormData();
        form.append("file", file);
        var xhr = new XMLHttpRequest();
        xhr.open("POST", "http://test.dakaqi.cn:3030/platform/welfareItem/upload", true);
        function callback() {
            if (xhr.readyState == 4) {
                $timeout(function () {
                    var data = angular.fromJson(xhr.responseText);
                    if (data.statusCode == 0) {
                        alert("上传成功!");
                        document.getElementById('docFile').outerHTML = obj.outerHTML;
                    } else {
                        alert(data.statusMessage);
                    }
                }, 3000);
            }
        }
        xhr.onreadystatechange = callback;
        xhr.send(form);
    }
}]);